package com.gnerv.battle.boot.framework.core.tools;

import java.lang.reflect.Method;
import java.util.Arrays;

/**
 * 反射 工具类
 * @author Gnerv LiGen
 */
public class ReflectTools {

    private ReflectTools() {
    }

    public static Class<?> getClass(String className) {
        try {
            return Class.forName(className);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e.getMessage());
        }
    }

    public static Method getMethod(String fullName) {
        String className = fullName.substring(0, fullName.lastIndexOf("."));
        String methodName = fullName.substring(fullName.lastIndexOf(".") + 1);
        Class<?> clazz = getClass(className);
        return getMethod(clazz, methodName);
    }

    public static Method getMethod(Class<?> clazz, String name) {
        return Arrays.stream(clazz.getMethods()).filter(method -> method.getName().equals(name)).findFirst().orElse(null);
    }

}
